package org.dtrd.modules.content.articles.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dtrd.modules.content.articles.entity.bean.CheckInfo;
import org.dtrd.modules.content.articles.entity.po.DtrdExtEmsYwCheckList;
import org.dtrd.modules.content.articles.mapper.DtrdExtEmsYwCheckListMapper;
import org.dtrd.modules.content.articles.service.IDtrdExtEmsYwCheckListService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
/**
@author 萧
@date 2021-08-25 17:37:46
**/
@Service
@DS("multi-datasource1")
public class DtrdExtEmsYwCheckListServiceImpl extends ServiceImpl<DtrdExtEmsYwCheckListMapper, DtrdExtEmsYwCheckList> implements IDtrdExtEmsYwCheckListService {

    @Override
    public IPage<DtrdExtEmsYwCheckList> getCheckList(Integer pageNum, Integer pageSize, Integer checkCategory,Integer checkStatus) {
        Page<DtrdExtEmsYwCheckList> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<DtrdExtEmsYwCheckList> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (checkCategory != null) {
            lambdaQueryWrapper.eq(DtrdExtEmsYwCheckList::getCheckCategoryid, checkCategory)
                    .eq(DtrdExtEmsYwCheckList::getCheckStatus,checkStatus);
        }
        lambdaQueryWrapper
                .eq(DtrdExtEmsYwCheckList::getIsDel, 0)
                .orderByDesc(DtrdExtEmsYwCheckList::getDataId);
        page = page(page, lambdaQueryWrapper);
        return page;
    }

    @Override
    public CheckInfo getCheckDesc(Integer dataId) {
        LambdaQueryWrapper<DtrdExtEmsYwCheckList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DtrdExtEmsYwCheckList::getIsDel,0)
                .eq(DtrdExtEmsYwCheckList::getDataId,dataId);
        DtrdExtEmsYwCheckList dtrdExtEmsYwCheckList = baseMapper.selectOne(queryWrapper);
        CheckInfo checkInfo = new CheckInfo();
        if (dtrdExtEmsYwCheckList != null) {
            BeanUtils.copyProperties(dtrdExtEmsYwCheckList, checkInfo);
        }
        return checkInfo;
    }
}
